package cn.iocoder.yudao.module.system.dal.mysql.oauth2;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.Oauth2ApproveDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * oauth2批准映射器
 *
 * @author huangweidong
 * @date 2023/05/09
 */
@Mapper
public interface Oauth2ApproveMapper extends BaseMapperX<Oauth2ApproveDO> {

    /**
     * 更新
     *
     * @param updateObj 更新obj
     * @return int
     */
    default int update(Oauth2ApproveDO updateObj) {
        return update(updateObj, new LambdaQueryWrapperX<Oauth2ApproveDO>()
                .eq(Oauth2ApproveDO::getUserId, updateObj.getUserId())
                .eq(Oauth2ApproveDO::getUserType, updateObj.getUserType())
                .eq(Oauth2ApproveDO::getClientId, updateObj.getClientId())
                .eq(Oauth2ApproveDO::getScope, updateObj.getScope()));
    }

    /**
     * 查询列表通过用户id和用户类型和客户端id
     *
     * @param userId   用户id
     * @param userType 用户类型
     * @param clientId 客户机id
     * @return {@code List<Oauth2ApproveDO>}
     */
    default List<Oauth2ApproveDO> selectListByUserIdAndUserTypeAndClientId(Long userId, Integer userType, String clientId) {
        return selectList(new LambdaQueryWrapperX<Oauth2ApproveDO>()
                .eq(Oauth2ApproveDO::getUserId, userId)
                .eq(Oauth2ApproveDO::getUserType, userType)
                .eq(Oauth2ApproveDO::getClientId, clientId));
    }

}
